# Maintainer: Peter Budai <peterbudai@hotmail.com>

_realname=scikit-learn
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}"  "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.19.1
pkgrel=1
pkgdesc="A set of python modules for machine learning and data mining (mingw-w64)"
arch=('any')
url='http://scikit-learn.sourceforge.net/'
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-scipy"
             "${MINGW_PACKAGE_PREFIX}-python3-scipy"
             "${MINGW_PACKAGE_PREFIX}-cython2"
             "${MINGW_PACKAGE_PREFIX}-cython"
             )
source=("${_realname}-${pkgver}.tar.gz::https://github.com/scikit-learn/${_realname}/archive/${pkgver}.tar.gz"
          001-10342.patch)
sha256sums=('2947f531ad52e81b2436b26608d8198778ac0b4baa7d2925db8b3b3fcb39c8a2'
            'fc2cc84cc0cc3f049f275813e8b5ff17efa14b03ae96be166946588b1bf28276')

prepare() {
  cd "$srcdir"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-10342.patch

  cd "$srcdir"/

  for pver in {2,3}; do
    rm -rf python${pver}-build-${CARCH} | true
    cp -r "${_realname}-${pkgver}" "python${pver}-build-${CARCH}"
  done

  # python -> python2 rename
  find python2-build-${CARCH} -name '*py' -exec sed -e 's_#!/usr/bin/env python_&2_' -i {} \;

}

build() {
  for pver in {2,3}; do
    msg "Python ${pver} build for ${CARCH}"
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done
}

package_python3-scikit-learn() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3"
           "${MINGW_PACKAGE_PREFIX}-python3-scipy"
            )

  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -D COPYING "$pkgdir"/${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE

  install -d "$pkgdir"/${MINGW_PREFIX}/share/doc/python3-${_realname}
  cp -r doc/tutorial "$pkgdir"/${MINGW_PREFIX}/share/doc/python3-${_realname}/tutorial
}

package_python2-scikit-learn() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2"
           "${MINGW_PACKAGE_PREFIX}-python2-scipy"
            )

  cd "${srcdir}/python2-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -D COPYING "$pkgdir"/${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE

  install -d "$pkgdir"/${MINGW_PREFIX}/share/doc/python2-${_realname}
  cp -r doc/tutorial "$pkgdir"/${MINGW_PREFIX}/share/doc/python2-${_realname}/tutorial
}

package_mingw-w64-i686-python2-scikit-learn() {
  package_python2-scikit-learn
}

package_mingw-w64-i686-python3-scikit-learn() {
  package_python3-scikit-learn
}

package_mingw-w64-x86_64-python2-scikit-learn() {
  package_python2-scikit-learn
}

package_mingw-w64-x86_64-python3-scikit-learn() {
  package_python3-scikit-learn
}
